package com.module.rotary.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.dq.util.NetWorkUtil;
import com.module.rotary.R;
import com.module.rotary.adapter.CashRewardsAdapter;
import com.module.rotary.config.RotaryManager;

public class CashRewardsActivity extends Activity {

    private ImageView imgBack;
    private TextView tvTitleRight;
    private RecyclerView recyclerView;
    private ConstraintLayout layoutNoData;
    private CashRewardsAdapter rewardsAdapter;

    public static void startAct(Activity activity) {
        Intent intent = new Intent(activity, CashRewardsActivity.class);
        activity.startActivity(intent);
    }

    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
        setContentView(R.layout.activity_cash_rewards);
        initView();
    }

    private void initView() {
        imgBack = findViewById(R.id.imgBack);
        tvTitleRight = findViewById(R.id.tvTitleRight);
        layoutNoData = findViewById(R.id.layoutNoData);
        recyclerView = findViewById(R.id.recyclerView);

        tvTitleRight.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        rewardsAdapter = new CashRewardsAdapter();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(rewardsAdapter);
        rewardsAdapter.setList(RotaryManager.getInstance().getData());

        if (!NetWorkUtil.isNetworkConnected(this)) {
            layoutNoData.setVisibility(View.VISIBLE);
        }

        initLister();
    }

    private void initLister() {
        imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tvTitleRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ForRecordActivity.startAct(CashRewardsActivity.this);
            }
        });
    }
}
